package com.haochang.chunkvod.model.cash;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.haochang.base.BaseActivity;
import com.haochang.chunkvod.app.config.ApiConfig;
import com.haochang.chunkvod.app.utils.ToastUtils;
import com.haochang.chunkvod.model.order.RoomInfo;
import com.haochang.chunkvod.tools.thirdparty.network.http.httpenum.HttpCacheEnum;
import com.haochang.chunkvod.tools.thirdparty.network.http.httpenum.HttpMethodEnum;
import com.haochang.chunkvod.tools.thirdparty.network.http.httpenum.HttpRequestLoadingEnum;
import com.haochang.chunkvod.tools.thirdparty.network.http.request.HttpRequestBuilder;
import com.haochang.chunkvod.tools.thirdparty.network.http.request.HttpRequestTask;
import com.haochang.chunkvod.tools.vod.log.Logger;
import com.haochang.chunkvod.view.vod.dialog.DialogItemInfo;
import com.haochang.chunkvod.view.vod.spinner.SpinnerInfo;

import android.text.TextUtils;

/**
 *@author qintao
 *created at 2016/8/8 12:51
 * 收银数据请求
 */

public class CashData
{
	private BaseActivity context;

	public CashData(BaseActivity context)
	{
		this.context = context;
	}

	public interface IRoomStatusListener
	{
		public void onRequestSuccess(List<RoomInfo> list, List<SpinnerInfo> billStatusList, List<SpinnerInfo> sortList, VehicleInfo info, boolean clear);

		public void onFinish();
	}

	public interface ISetTimeListener
	{
		public void onRequestSuccess(JSONObject jsonObject);
	}

	public interface ICheckOutNumListener
	{
		public void onRequestSuccess(JSONObject jsonObject);

		public void onRequestFail(int errno, String errMsg);
	}

	public interface IRoomCheckOutListener
	{
		public void onRequestSuccess(JSONObject jsonObject);

		public void onRequestFail(int errno, String errMsg);
	}

	public interface IBillStatusRollBackListener
	{
		public void onRequestSuccess();
	}

	public interface IReasonListener
	{
		public void onRequestSuccess(List<DialogItemInfo> list);
	}

	public interface IShiftListener
	{
		public void onRequestSuccess();

		public void onRequestFail(int errno, String errMsg);
	}

	public interface INonOperatingRevenueListener
	{
		public void onRequestSuccess(List<GoodInfo> list);
	}

	public interface INonOperatingRevenueCheckOutListener
	{
		public void onRequestSuccess();

		public void onRequestFail(int errno, String errMsg);
	}

	public interface IPrintInfoListener
	{
		public void onRequestSuccess(JSONObject jsonObject);

		public void onRequestFail(int errno, String errMsg);
	}

	public interface IBuyOrderListener
	{
		public void onRequestSuccess(JSONObject jsonObject, List<GoodInfo> goodInfoList);

		public void onRequestFail(int errno, String errMsg);
	}

	public interface ResultResponseList<T>
	{
		void onRequestSuccess(List<T> list);

		void onRequestFail(int errno, String errMsg);
	}

	public interface ResultResponse
	{
		void onRequestSuccess();

		void onRequestFail(int errno, String errMsg);
	}

	/**
	 * 收银包房使用状态请求
	 * @param billStatus 账单状态
	 * @param sortType 排序类型
	 * @param areaIds 区域ids
	 * @param isLoading 是否加载转圈
	 * @param listener 网络请求监听
	 */
	public void requestCashRoomStatus(String billStatus, String sortType, String areaIds, boolean isShowTable, boolean isLoading,
			final IRoomStatusListener listener)
	{
		JSONArray jsonArray = new JSONArray();
		if (!TextUtils.isEmpty(areaIds))
		{
			String[] area_ids = areaIds.split(",");
			for (int i = 0; i < area_ids.length; i++)
			{
				if (!TextUtils.isEmpty(area_ids[i]))
					jsonArray.put(area_ids[i]);
			}
		}
		HashMap<String, String> map = new HashMap<String, String>();
		Logger.e(jsonArray.toString() + "");
		map.put("area_ids", jsonArray.toString());
		map.put("bill_status", billStatus);
		map.put("sort_type", sortType);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CASH_ROOMS_STATUS).param(map)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(isLoading ? HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT : HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							List<RoomInfo> list = parseRoomJson(jsonObject);
							List<SpinnerInfo> billStatusList = parseStatusJson(jsonObject);
							List<SpinnerInfo> sortList = parseSortJson(jsonObject);
							VehicleInfo info = parseVehicleInfo(jsonObject);
							if (listener != null)
							{
								listener.onRequestSuccess(list, billStatusList, sortList, info, true);
								listener.onFinish();
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (null != listener)
						{
							listener.onFinish();
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 设时获取默认值
	 * @param billId 账单id
	 * @param roomTypeId 房间类型id
	 * @param listener 网络请求监听
	 */
	public void requestDefaultTime(String billId, String roomTypeId, final ISetTimeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("room_type_id", roomTypeId);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.SETTIME).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(jsonObject);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 提交设时时间
	 * @param billId 账单id
	 * @param roomTypeId  房间类型id
	 * @param time 时间
	 * @param listener 网络请求监听
	 */
	public void requestSubmitTime(String billId, String roomTypeId, String time, final ISetTimeListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("room_type_id", roomTypeId);
		map.put("install_time", time);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.SETTIME).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取结账金额
	 * @param billId 账单id
	 * @param is_force 是否强制结账
	 * @param listener 网络请求监听
	 */
	public void requestCheckOutNum(String billId, String is_force, final ICheckOutNumListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("force", is_force);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CHECKOUT).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							if (listener != null)
							{
								listener.onRequestSuccess(jsonObject);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 账单状态回滚
	 * @param billId 账单id
	 * @param listener 网络请求监听
	 */
	public void requestBillStatusRollBack(String billId, final IBillStatusRollBackListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.ROLLBACK).param(map).httpMethodEnum(HttpMethodEnum.PUT)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess();
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 原因列表
	 * @param type 原因类型
	 * @param listener 网络请求监听
	 */
	public void requestReason(String type, final IReasonListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("type", type);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.REASON).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							List<DialogItemInfo> list = parseReasonData(jsonObject);
							listener.onRequestSuccess(list);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 挂账人列表
	 *  @param listener 网络请求监听
	 */
	public void requestCredit(final IReasonListener listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CUSTOMER_CREDIT).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							List<DialogItemInfo> list = parseCreditData(jsonObject);
							listener.onRequestSuccess(list);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 班次创建
	 * @param listener 网络请求监听
	 */
	public void requestShift(final IShiftListener listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.SHIFT).param(null).httpMethodEnum(HttpMethodEnum.POST)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess();
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取营业外商品数据
	 * @param listener 网络请求监听
	 */
	public void requestNonOperatingRevenueGoods(final INonOperatingRevenueListener listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.NONREVENUE_GOODS).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							List<GoodInfo> list = parseNonOperateGoodsData(jsonObject);
							listener.onRequestSuccess(list);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 营业外商品数据结算
	 * @param cash 现金
	 * @param thirdType 第三方支付类型
	 * @param thirdNum 第三方支付金额
	 * @param authCode 二维码
	 * @param detail 赔偿清单详情
	 * @param listener 网络请求监听
	 */
	public void requestNonOperatingRevenueGoodsCheckOut(int cash, String thirdType, int thirdNum, String authCode, String detail,
			final INonOperatingRevenueCheckOutListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("cash", cash + "");
		map.put("third_pay_method", thirdType);
		map.put("third_pay_amount", thirdNum + "");
		if (!TextUtils.isEmpty(authCode))
			map.put("auth_code", authCode);
		map.put("detail", detail);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.NONREVENUE_GOODS).param(map)
				.httpMethodEnum(HttpMethodEnum.POST).isPullToRefresh(true).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_PAY).httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess();
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取赔偿清单数据
	 * @param listener 网络请求监听
	 */
	public void requestPayForGoods(final INonOperatingRevenueListener listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.NONREVENUE_REPARATION).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							List<GoodInfo> list = parseNonOperateGoodsData(jsonObject);
							listener.onRequestSuccess(list);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (!TextUtils.isEmpty(errMsg))
							ToastUtils.showText(context, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 赔偿结算
	 * @param cash 现金
	 * @param thirdType 第三方支付类型
	 * @param thirdNum 第三方支付金额
	 * @param authCode 二维码
	 * @param detail 赔偿清单详情
	 * @param listener 网络请求监听
	 */
	public void requestPayForGoodsCheckOut(int cash, String thirdType, int thirdNum, String authCode, String detail,
			final INonOperatingRevenueCheckOutListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("cash", cash + "");
		map.put("third_pay_method", thirdType);
		map.put("third_pay_amount", thirdNum + "");
		if (!TextUtils.isEmpty(authCode))
			map.put("auth_code", authCode);
		map.put("detail", detail);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.NONREVENUE_REPARATION).param(map)
				.httpMethodEnum(HttpMethodEnum.POST).isPullToRefresh(true).localCache(HttpCacheEnum.ENABLE_VALID)
				.httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_PAY).httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess();
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 房间结账
	 * @param billId 账单id
	 * @param receivableType 收款类型
	 * @param payTime 支付时间
	 * @param payReason 免单原因
	 * @param creditCustomerId 挂账人id
	 * @param payData 支付数据
	 * @param listener 网络请求监听
	 */
	public void requestRoomCheckOut(String billId, String receivableType, String payTime, String payReason, String creditCustomerId, String payData,
			final IRoomCheckOutListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		map.put("receivable_type", receivableType);
		map.put("pay_time", payTime);
		if (!TextUtils.isEmpty(creditCustomerId))
			map.put("credit_customer_id", creditCustomerId);
		if (!TextUtils.isEmpty(payReason))
			map.put("pay_reason", payReason);
		map.put("pay_data", payData);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CHECKOUT).param(map).httpMethodEnum(HttpMethodEnum.POST)
				.localCache(HttpCacheEnum.ENABLE_VALID).isPullToRefresh(true).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_PAY)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取买单信息
	 * @param billId 账单id
	 * @param listener 网络请求监听
	 */
	public void requestBuyOrderInfo(String billId, final IBuyOrderListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CASH_BUY_ORDER).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (jsonObject != null)
						{
							List<GoodInfo> infolist = null;
							if (listener != null)
							{
								listener.onRequestSuccess(jsonObject, infolist);
							}
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取预付款基本信息
	 * @param billId 账单id
	 * @param listener 网络请求监听
	 */
	public void requestPrintPrePayInfo(String billId, final IPrintInfoListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.PRINT_PRE_PAY).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取预结列印信息
	 * @param billId 账单id
	 * @param listener 网络请求监听
	 */
	public void requestPreCheckOutInfo(String billId, final IPrintInfoListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.PRE_CHECK_OUT).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取结账列印信息
	 * @param billId 账单id
	 * @param listener 网络请求监听
	 */
	public void requestCheckOutInfo(String billId, final IPrintInfoListener listener)
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("bill_id", billId);
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CHECK_OUT).param(map).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_NONE)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取汇总列印信息
	 * @param listener 网络请求监听
	 */
	public void requestCollectionInfo(final IPrintInfoListener listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.COLLECTION).param(null).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取紧急列印信息
	 * @param listener 网络请求监听
	 */
	public void requestUrgencyInfo(final IPrintInfoListener listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.URGENCY).param(null).httpMethodEnum(HttpMethodEnum.GET)
				.localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(jsonObject);
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 获取券列表
	 * @param listener 网络请求监听
	 */
	@SuppressWarnings("unchecked")
	public void requestCouponList(final ResultResponseList listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CASH_COUPON_LIST).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
						{
							listener.onRequestSuccess(new ArrayList<CouponInfo>());
						}
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
						{
							listener.onRequestFail(errno, errMsg);
						}
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 添加券
	 * @param listener 网络请求监听
	 */
	@SuppressWarnings("unchecked")
	public void requestAddCoupon(final ResultResponse listener)
	{
		HttpRequestTask httpRequestTask = new HttpRequestBuilder(context).interfaceName(ApiConfig.CASH_ADD_COUPON).param(null)
				.httpMethodEnum(HttpMethodEnum.GET).localCache(HttpCacheEnum.ENABLE_VALID).httpRequestLoadingEnum(HttpRequestLoadingEnum.HTTP_LOADING_DEFAULT)
				.httpRequestSucessListener(new HttpRequestBuilder.IHttpRequestSucessListener()
				{

					@Override
					public void onResponseSucess(JSONObject jsonObject)
					{
						if (listener != null)
							listener.onRequestSuccess();
					}
				}).httpRequestFailedListener(new HttpRequestBuilder.IHttpRequestFailedListener()
				{

					@Override
					public void onError(int errno, String errMsg)
					{
						if (listener != null)
							listener.onRequestFail(errno, errMsg);
					}
				}).build();
		httpRequestTask.execute();
	}

	/**
	 * 解析包房
	 *
	 * @param jsonObject jsonObject
	 * @return 房间信息列表
	 */
	private List<RoomInfo> parseRoomJson(JSONObject jsonObject)
	{
		ArrayList<RoomInfo> roomInfoList = new ArrayList<RoomInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("rooms_info");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				RoomInfo info = new RoomInfo();

				info.setRoomId(jObject.optString("room_id"));
				info.setRoomNum(jObject.optString("room_code"));
				info.setRoomTypeId(jObject.optString("room_type_id"));
				info.setRoomType(jObject.optString("room_type_name"));
				info.setRoomPeopleCount(jObject.optInt("customer_count"));
				info.setRoomStatus(jObject.optString("room_status"));
				info.setStart_time(jObject.optString("bill_begin_time"));
				info.setEnd_time(jObject.optString("bill_end_time"));
				info.setBillId(jObject.optString("bill_id"));
				info.setBillStatus(jObject.optString("bill_status"));
				info.setUsage(jObject.optString("usage"));
				info.setIsHonor(jObject.optInt("is_honor"));
				roomInfoList.add(info);
			}
		}
		return roomInfoList;
	}

	/**
	 *  解析状态
	 * @param jsonObject jsonObject
	 * @return 状态排序列表
	 */
	private List<SpinnerInfo> parseStatusJson(JSONObject jsonObject)
	{
		ArrayList<SpinnerInfo> infoList = new ArrayList<SpinnerInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("bill_current_status");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				SpinnerInfo info = new SpinnerInfo();
				info.setCode(jObject.optString("status"));
				info.setCount(jObject.optInt("count"));
				info.setName(jObject.optString("name") + "(" + info.getCount() + ")");
				infoList.add(info);
			}
		}
		return infoList;
	}

	/**
	 *  解析排序
	 * @param jsonObject jsonObject
	 * @return 房间排序信息
	 */
	private List<SpinnerInfo> parseSortJson(JSONObject jsonObject)
	{
		ArrayList<SpinnerInfo> infoList = new ArrayList<SpinnerInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("sort_types");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				SpinnerInfo info = new SpinnerInfo();
				info.setCode(jObject.optString("id"));
				info.setName(jObject.optString("title"));
				infoList.add(info);
			}
		}
		return infoList;
	}

	/**
	 *  解析班次
	 * @param jsonObject jsonObject
	 * @return  班次信息
	 */
	private VehicleInfo parseVehicleInfo(JSONObject jsonObject)
	{
		VehicleInfo info = new VehicleInfo();

		info.setBusiness_date(jsonObject.optString("current_day"));
		info.setMachine_ip(jsonObject.optString("machine_ip"));
		info.setStaff_name(jsonObject.optString("staff_name"));
		info.setShiftName(jsonObject.optString("current_shift_name"));
		info.setCurrent_shift_begin_time(jsonObject.optString("current_shift_begin_time"));
		info.setCurrent_shift_end_time(jsonObject.optString("current_shift_end_time"));
		return info;
	}

	/**
	 * 解析原因
	 * @param jsonObject jsonObject
	 * @return 原因列表
	 */
	private List<DialogItemInfo> parseReasonData(JSONObject jsonObject)
	{
		List<DialogItemInfo> infoList = new ArrayList<DialogItemInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("list");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				try
				{
					String object = jsonArray.getString(i);
					DialogItemInfo info = new DialogItemInfo();
					if (i == 0)
						info.setSelected(true);
					info.setName(object);
					infoList.add(info);
				} catch (JSONException e)
				{
					e.printStackTrace();
				}
			}
		}
		return infoList;
	}

	/**
	 * 解析挂账人列表
	 * @param jsonObject jsonObject
	 * @return 挂账人列表
	 */
	private List<DialogItemInfo> parseCreditData(JSONObject jsonObject)
	{
		List<DialogItemInfo> infoList = new ArrayList<DialogItemInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("list");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				DialogItemInfo info = new DialogItemInfo();
				if (i == 0)
					info.setSelected(true);
				info.setCode(jObject.optString("id"));
				info.setName(jObject.optString("name"));
				infoList.add(info);
			}
		}
		return infoList;
	}

	/**
	 * 解析营业外商品数据
	 * @param jsonObject jsonObject
	 * @return 商品列表
	 */
	private List<GoodInfo> parseNonOperateGoodsData(JSONObject jsonObject)
	{
		List<GoodInfo> infoList = new ArrayList<GoodInfo>();
		JSONArray jsonArray = jsonObject.optJSONArray("data");
		if (jsonArray != null && jsonArray.length() > 0)
		{
			for (int i = 0; i < jsonArray.length(); i++)
			{
				JSONObject jObject = jsonArray.optJSONObject(i);
				if (jObject == null)
					continue;
				GoodInfo info = new GoodInfo();
				info.setMateriel_code(jObject.optString("coding"));
				info.setGoodsId(jObject.optString("id"));
				info.setGoodsName(jObject.optString("name"));
				info.setUnit(jObject.optString("unit"));
				info.setPrice(jObject.optInt("value"));
				infoList.add(info);
			}
		}
		return infoList;
	}
}
